import pandas as pd
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')

class ClusterUtils(object):

    def __init__(self):
        self.df = pd.read_csv('./scenic_data.csv')

    def get_cluster(self):
        # 提取特征并标准化
        features = self.df[['non_weekend_ratio', 'out_province_ratio', 'elderly_ratio']]
        scaler = StandardScaler()
        scaler_features = scaler.fit_transform(features)
        # 使用K-Means聚类
        kmeans = KMeans(n_clusters=4, random_state=42)
        self.df['cluster'] = kmeans.fit_predict(scaler_features)
        # 查看聚类结果
        print(self.df[['tourist_agency_name', 'cluster']])

if __name__ == '__main__':
    cu = ClusterUtils()
    cu.get_cluster()